﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using VoteServer.Member;

namespace VoteServer
{
    public class FileServer//文件服务--服务于数据层
    {
        public Object ReadFile(String path) {
            try
            {
                
                FileStream fsr = new FileStream(path, FileMode.Open, FileAccess.Read);
                Object o = new BinaryFormatter().Deserialize(fsr);
                fsr.Close();
                return o;
            }
            catch (Exception e)
            {
                return null;
                Console.WriteLine(e.Message);

            }

        }

        public void WriteFile(String path, Object oj) {
            try
            {
               
                FileStream fsw = new FileStream(path, FileMode.Create, FileAccess.Write);
                new BinaryFormatter().Serialize(fsw, oj);
                fsw.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

            }

        }

        public void WriteFile_Problem(List<Problem> oj) {
            //待写
        }

        public void WriteFile_Users(List<User> user) {
        }
    }
}

